diff --git a/src/_pytest/mark/legacy.py b/src/_pytest/mark/legacy.py
index eb50340f2..4a40b264b 100644
--- a/src/_pytest/mark/legacy.py
+++ b/src/_pytest/mark/legacy.py
@@ -29,6 +29,9 @@ class MarkMapping:
     def __getitem__(self, name):
         return name in self.own_mark_names
 
+    def as_dict(self):
+        return {name: True for name in self.own_mark_names}
+
 
 @attr.s
 class KeywordMapping:
@@ -76,6 +79,9 @@ class KeywordMapping:
                 return True
         return False
 
+    def as_dict(self):
+        return {name.lower(): True for name in self._names}
+
 
 python_keywords_allowed_list = ["or", "and", "not"]
 
@@ -83,7 +89,8 @@ python_keywords_allowed_list = ["or", "and", "not"]
 def matchmark(colitem, markexpr):
     """Tries to match on any marker names, attached to the given colitem."""
     try:
-        return eval(markexpr, {}, MarkMapping.from_item(colitem))
+        mark_mapping = MarkMapping.from_item(colitem).as_dict()
+        return eval(markexpr, {}, mark_mapping)
     except Exception:
         raise UsageError("Wrong expression passed to '-m': {}".format(markexpr))
 
@@ -97,12 +104,12 @@ def matchkeyword(colitem, keywordexpr):
     Additionally, matches on names in the 'extra_keyword_matches' set of
     any item, as well as names directly assigned to test functions.
     """
-    mapping = KeywordMapping.from_item(colitem)
+    keyword_mapping = KeywordMapping.from_item(colitem).as_dict()
     if " " not in keywordexpr:
         # special case to allow for simple "-k pass" and "-k 1.3"
-        return mapping[keywordexpr]
+        return keyword_mapping.get(keywordexpr.lower(), False)
     elif keywordexpr.startswith("not ") and " " not in keywordexpr[4:]:
-        return not mapping[keywordexpr[4:]]
+        return not keyword_mapping.get(keywordexpr[4:].lower(), False)
     for kwd in keywordexpr.split():
         if keyword.iskeyword(kwd) and kwd not in python_keywords_allowed_list:
             raise UsageError(
@@ -111,6 +118,6 @@ def matchkeyword(colitem, keywordexpr):
                 )
             )
     try:
-        return eval(keywordexpr, {}, mapping)
+        return eval(keywordexpr, {}, keyword_mapping)
     except Exception:
         raise UsageError("Wrong expression passed to '-k': {}".format(keywordexpr))
